package com.td.framework.kqxt.pbgl.action;

import java.util.Date;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.td.framework.common.AbstractAction;
import com.td.framework.kqxt.domain.KqBcsz;
import com.td.framework.webmanager.page.PageService;

public class BcszAction extends AbstractAction {
	//实体对象
    private KqBcsz  kqBcsz;
    //班次设置对象集合
    private List<KqBcsz> bcszList;
    //查询条件
    private String bcmc;//班次名称
    private Log log = LogFactory.getLog(BcszAction.class);
    
    //=======================================================排班设置 	START======================================
    
    /**
     * 排班列表集合
     * @return
     */
    public String listBcsz(){
    	String hql ="from KqBcsz t";    	
    	int rows = this.getBaseService().getRowsByListHql(hql);				
		page = PageService.getPage(rows, currentPage, pageSize, pageMethod);
		this.setCurrentPage(page.getCurentPage());		
		this.setPageSize(page.getPageSize());
		bcszList =this.getBaseService().getPageList(hql,page.getStartRow(),pageSize);
		return "listBcsz";
    }
    
    /**
     * 打开班次添加页面
     */
    public String createBcszForm(){
    	this.setEditState(1);
    	return "createBcsz";
    }
    
    /**
     * 添加班次信息
     * @return
     */
    public String createBcsz(){
    	this.setEditState(1);
	   boolean flag = false;
		try {
			/*String pyzt = ChineseTools.getFirstLetter(kqBcsz.getBcmc());
			kqBcsz.setPyzt(pyzt);*/
			kqBcsz.setCzry(getUserInfo().getYhm());
			kqBcsz.setCzsj(new Date());
			flag = this.getBaseService().saveEntity(kqBcsz);
		} catch (Exception e) {
			 log.error("增加班次信息失败："+e.getMessage());
			 this.handleMessage("info", "添加失败,联系管理员!");
		}
		if(flag = true){
	    	 this.handleMessage("info", "添加成功，请继续操作!");
	     }
	     return "createBcsz";
    }
    
    /**
     *打开修改页面 
     * @return
     */
    public String reworkBcszForm(){
    	this.setEditState(2);
    	kqBcsz = (KqBcsz) this.getBaseService().getEntityById(KqBcsz.class,zids[0]);
    	return "reworkBcsz";
    }
    
    /**
     * 修改代码表信息
     * @return
     */
    public String reworkBcsz(){
    	this.setEditState(2);
    	 boolean flag = false;
 		try {
 			kqBcsz.setXgry(getUserInfo().getYhm());
			kqBcsz.setXgsj(new Date());
 			flag = this.getBaseService().saveOrUpdate(kqBcsz);
 		} catch (Exception e) {
 			log.error("修改班次设置失败："+e.getMessage());
 			 this.handleMessage("info", "修改失败,请联系管理员!");
 		}
 	     if(flag = true){
 	    	 this.handleMessage("info", "修改成功!");
 	     }
 	     return "reworkBcsz"; 
    }
    
    /**
     * 删除选中班次的信息
     * @return
     */
    public String removeBcsz(){
    	 boolean flag = false;
  	     flag = this.getBaseService().deleteBatch(KqBcsz.class, zids);
  	     return "listBcsz"; 
    }
    
    /**
     *打开班次设置展现页面
     * @return
     */
    public String showBcsz(){
    	this.setEditState(3);
    	kqBcsz = (KqBcsz) this.getBaseService().getEntityById(KqBcsz.class,zids[0]);
    	return "showBcsz";
    }
    
	public KqBcsz getKqBcsz() {
		return kqBcsz;
	}

	public void setKqBcsz(KqBcsz kqBcsz) {
		this.kqBcsz = kqBcsz;
	}

	public List<KqBcsz> getBcszList() {
		return bcszList;
	}

	public void setBcszList(List<KqBcsz> bcszList) {
		this.bcszList = bcszList;
	}

	public String getBcmc() {
		return bcmc;
	}

	public void setBcmc(String bcmc) {
		this.bcmc = bcmc;
	}   
}
